#!/bin/bash
#判断跳板机上是否存在某工程版本

error_exit(){
	echo "ERROR: 判断跳板机上是否存在某工程版本失败,$1,jumpServerIp=${jumpServerIp},editionPath=${editionPath}" >> ${logFile}
	echo "ERROR: 判断跳板机上是否存在某工程版本失败,$1,jumpServerIp=${jumpServerIp},editionPath=${editionPath}"
	exit 1
}


jumpServerIp=$1
editionPath=$2
ssh_login_user=$3
ssh_key_file=$4
ssh_port=$5
logFile=$6
shellPath=$7

loginUser=`whoami`
ssh_key_file=/home/${loginUser}/${ssh_key_file}

echo "判断跳板机上是否存在某工程版本开始,jumpServerIp=${jumpServerIp},editionPath=${editionPath}" >> ${logFile}

#校验远程终端是否可以免密登录
expect ${shellPath}/shell/init/beetle_validate_ssh.sh ${jumpServerIp} ${ssh_login_user} ${ssh_login_user} ${ssh_port} > /dev/null || error_exit "校验ssh免密登录失败"

ssh ${ssh_login_user}@${jumpServerIp} -p ${ssh_port} -i ${ssh_key_file} "ls ${editionPath}" || error_exit

echo "判断跳板机上是否存在某工程版本结束,jumpServerIp=${jumpServerIp},editionPath=${editionPath}" >> ${logFile}